#include<iostream>
#include<vector>
#include<string>
#include<unordered_map>
using namespace std;

class Solution {
public:

    string GetString(const string& s, int begin, int len)
    {
        string str;
        while (len--)
        {
            str += s[begin++];
        }
        return str;
    }

    vector<int> findSubstring(string s, vector<string>& words) {
        unordered_map<string, int> m;
        vector<int> ret;
        int n = words[0].size();
        int len = words.size();
        if (n * len > s.size())
            return ret;

        for (auto& str : words)
        {
            m[str]++;
        }
        int left = 0, right = 0, count = 0;
        int i = 0;
        while (i < n)
        {
            right = i++;
            left = right;
            count = 0;
            unordered_map<string, int> sm;
            while (right < s.size())
            {
                if (right + n > s.size())
                    break;
                string str = GetString(s, right, n);
                cout << str << endl;
                right += n;
                if (++sm[str] <= m[str])
                    count++;
                cout << left << right << endl;
                cout << count << endl;
                if (count == len)
                    ret.push_back(left);
                if ((right - left) / n >= len)
                {
                    string str = GetString(s, left, n);
                    if (sm[str]-- <= m[str])
                        count--;
                    left += n;
                }
            }
        }
        return ret;
    }
};